home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / dev / gg / ncurses-5.3.lha / ncurses-5.3 / Ada95 / samples / ncurses2-flushinp_test.adb < prev    next >
Text File  |  2002-10-24  |  6KB  |  136 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                       GNAT ncurses Binding Samples                       --
  4. --                                                                          --
  5. --                                 ncurses                                  --
  6. --                                                                          --
  7. --                                 B O D Y                                  --
  8. --                                                                          --
  9. ------------------------------------------------------------------------------
  10. -- Copyright (c) 2000 Free Software Foundation, Inc.                        --
  11. --                                                                          --
  12. -- Permission is hereby granted, free of charge, to any person obtaining a  --
  13. -- copy of this software and associated documentation files (the            --
  14. -- "Software"), to deal in the Software without restriction, including      --
  15. -- without limitation the rights to use, copy, modify, merge, publish,      --
  16. -- distribute, distribute with modifications, sublicense, and/or sell       --
  17. -- copies of the Software, and to permit persons to whom the Software is    --
  18. -- furnished to do so, subject to the following conditions:                 --
  19. --                                                                          --
  20. -- The above copyright notice and this permission notice shall be included  --
  21. -- in all copies or substantial portions of the Software.                   --
  22. --                                                                          --
  23. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  --
  24. -- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               --
  25. -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   --
  26. -- IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   --
  27. -- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    --
  28. -- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    --
  29. -- THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               --
  30. --                                                                          --
  31. -- Except as contained in this notice, the name(s) of the above copyright   --
  32. -- holders shall not be used in advertising or otherwise to promote the     --
  33. -- sale, use or other dealings in this Software without prior written       --
  34. -- authorization.                                                           --
  35. ------------------------------------------------------------------------------
  36. --  Author: Eugene V. Melaragno <aldomel@ix.netcom.com> 2000
  37. --  Version Control
  38. --  $Revision: 1.1 $
  39. --  Binding Version 01.00
  40. ------------------------------------------------------------------------------
  41. with Terminal_Interface.Curses; use Terminal_Interface.Curses;
  42. with ncurses2.util; use ncurses2.util;
  43.  
  44. procedure ncurses2.flushinp_test (win : Window) is
  45.  
  46.    procedure Continue (win : Window);
  47.  
  48.    procedure Continue (win : Window) is
  49.    begin
  50.       Set_Echo_Mode (False);
  51.       Move_Cursor (win, 10, 1);
  52.       Add (win, 10, 1, " Press any key to continue");
  53.       Refresh (win);
  54.       Getchar (win);
  55.    end Continue;
  56.  
  57.    h, by, sh : Line_Position;
  58.    w, bx, sw : Column_Position;
  59.  
  60.    subWin : Window;
  61.  
  62. begin
  63.    Clear (win);
  64.    Get_Size (win, h, w);
  65.    Get_Window_Position (win, by, bx);
  66.    sw := w / 3;
  67.    sh := h / 3;
  68.    subWin := Sub_Window (win, sh, sw, by + h - sh - 2, bx + w - sw - 2);
  69.  
  70.    if Has_Colors then
  71.       Init_Pair (2, Cyan, Blue);
  72.       Change_Background (subWin,
  73.                          Attributed_Character'(Ch => ' ', Color => 2,
  74.                                                Attr => Normal_Video));
  75.    end if;
  76.  
  77.    Set_Character_Attributes (subWin,
  78.                              (Bold_Character => True, others => False));
  79.    Box (subWin);
  80.    Add (subWin, 2, 1, "This is a subwindow");
  81.    Refresh (win);
  82.  
  83.    Set_Cbreak_Mode (True);
  84.    Add (win, 0, 1, "This is a test of the flushinp() call.");
  85.  
  86.    Add (win, 2, 1, "Type random keys for 5 seconds.");
  87.    Add (win, 3, 1,
  88.         "These should be discarded (not echoed) after the subwindow " &
  89.         "goes away.");
  90.    Refresh (win);
  91.  
  92.    for i in 0 .. 4 loop
  93.       Move_Cursor (subWin, 1, 1);
  94.       Add (subWin, Str => "Time = ");
  95.       Add (subWin, Str => Integer'Image (i));
  96.       Refresh (subWin);
  97.       Nap_Milli_Seconds (1000);
  98.       Flush_Input;
  99.    end loop;
  100.  
  101.    Delete (subWin);
  102.    Erase (win);
  103.    Flash_Screen;
  104.    Refresh (win);
  105.    Nap_Milli_Seconds (1000);
  106.  
  107.    Add (win, 2, 1,
  108.         Str => "If you were still typing when the window timer expired,");
  109.    Add (win, 3, 1,
  110.         "or else you typed nothing at all while it was running,");
  111.    Add (win, 4, 1,
  112.         "test was invalid.  You'll see garbage or nothing at all. ");
  113.    Add (win, 6, 1, "Press a key");
  114.    Move_Cursor (win, 9, 10);
  115.    Refresh (win);
  116.    Set_Echo_Mode (True);
  117.    Getchar (win);
  118.    Flush_Input;
  119.    Add (win, 12, 0,
  120.         "If you see any key other than what you typed, flushinp() is broken.");
  121.    Continue (win);
  122.  
  123.    Move_Cursor (win, 9, 10);
  124.    Delete_Character (win);
  125.    Refresh (win);
  126.    Move_Cursor (win, 12, 0);
  127.    Clear_To_End_Of_Line;
  128.    Add (win,
  129.         "What you typed should now have been deleted; if not, wdelch() " &
  130.         "failed.");
  131.    Continue (win);
  132.  
  133.    Set_Cbreak_Mode (True);
  134.  
  135. end ncurses2.flushinp_test;
  136.